package com.mfp.java.testYou.ui.mvc;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mfp.java.testYou.core.AppContext;
import com.mfp.java.testYou.core.servlets.ManageUserServlet;
import com.mfp.java.testYou.db.model.User;
import com.mfp.java.testYou.model.UiSelectPair;


public class UsersPage extends AbstractMVC {
	
	public static final String URL = "/testYou/pages/users.jsp";
	
	private static final Integer LIST_SIZE = 10;

	public UsersPage(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
		prepareList();
	}
	
	private void prepareList(){
		List<User> list = AppContext.getDAO().getAllUsers();
		List<UiSelectPair> uiList = new LinkedList<UiSelectPair>();
		for (User u : list){
			uiList.add(new UiSelectPair(u.getUserName(), u.getId()));
		}

		
		getRequest().setAttribute(SelectListComponent.ATTR_LIST_DATA, uiList);
		getRequest().setAttribute(SelectListComponent.ATTR_LIST_NAME, ManageUserServlet.INPUT_USERID);
		getRequest().setAttribute(SelectListComponent.ATTR_LIST_SIZE, LIST_SIZE);
	}
}
